package com.sky.mq.rabbit;

import com.rabbitmq.client.Channel;
import com.sky.configuration.RabbitMQConfig;
import com.sky.mapper.OrderMapper;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * 消息队列接收消息
 */
@Component
public class ReceiveRabbitMQ {
    @Autowired
    private OrderMapper orderMapper;

    /**
     * @param orderId 要取消的订单的编号
     * @param msg     包含了要回复的队列
     * @param channel 有回复功能的参数
     */
    @RabbitListener(queues = RabbitMQConfig.ORDER_DEAD_QUEUE)
    public void ReceiveDeadOrder(Long orderId, Channel channel, Message msg) throws IOException {
        orderMapper.delCancelOrder(orderId);//查询数据库，订单是否付款，未付款：改为已取消
        channel.basicAck(msg.getMessageProperties().getDeliveryTag(),//应答的消息
                false//是否批量应答
        );
    }
}
